define(["angularAMD"], function (angularAMD) {
    angularAMD.service('B0213Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog', '$calculater', '$mddProvider',
        function ($rootScope, $filter, $translate, config, $MMWService, $mdDialog, $calculater, $mddProvider) {
            /**
             * options : {
             *     plot_detail, //plot資訊(多筆)
             *     machine_no, //機器編號
             *     option, //重工的類型(0:重工/1:讓步/2:跳站/3:跳流程)
             *     parent, //呼叫的程式
             *     feedback, //按下確定後要執行的內容
             *     confirm, //按下確定按鈕後，不呼叫服務時執行的內容
             *     back //按下關閉後執行的內容
             * }
             */
            this.init = function (options) {
                options.enable = {
                    op_no: true,
                    process: true,
                    reason_detail: true,
                    memo: true
                };
                options.option = options.option || '0';
                options.machine_no = options.machine_no || '';
                var plotItem = {
                    qty: 0,
                    reworkQty: 0,
                    assign_op_no: '',
                    assign_process: '',
                    assign_process_op_no: '',
                    reason_detail: []
                    //unit_conversion : 0
                };
                if (options.plot_detail.length > 0) {
                    plotItem.op_no = options.plot_detail[0].op_no;
                    plotItem.plot_no = options.plot_detail[0].plot_no;
                    plotItem.plot_detail = options.plot_detail;
                    var old_key;
                    options.plot_detail.forEach(function (detail) {
                        var key = '';
                        if (options.option == '1') {
                            //重工
                            key = detail.op_no + detail.process_no + detail.process_ver;
                        } else if (options.option == '2') {
                            key = detail.process_no + detail.process_ver;
                        }

                        if (!old_key) {
                            old_key = key;
                        } else if (old_key != key) {
                            //只能使用指定流程
                            options.enable['op_no'] = false;
                        }

                        detail.plot_stamp = detail.plot_stamp || '';
                        detail.status = detail.status || '';

                        plotItem.qty = $calculater.decimalAdd((+plotItem.qty), (+detail.qty));
                        if (options.parent == 'B0402') {
                            plotItem.reworkQty = $calculater.decimalAdd((+plotItem.reworkQty), (+detail.judge_qty));
                        } else {
                            plotItem.reworkQty = $calculater.decimalAdd((+plotItem.reworkQty), (+detail.qty));
                        }
                    });
                    // 20230822 modify by wenwei for M#131125 取消備註欄位卡控
                    if (options.parent == 'B0209') {
                        if (options.option == '1') {
                            options.enable['op_no'] = true;
                            options.enable['process'] = false;
                            options.enable['reason_detail'] = false;
                        } else if (options.option == '2') {
                            options.enable['op_no'] = true;
                            options.enable['process'] = false;
                            options.enable['reason_detail'] = false;
                        } else if (options.option == '3') {
                            options.enable['op_no'] = false;
                            options.enable['process'] = true;
                            options.enable['reason_detail'] = false;
                        }
                    } else if (options.parent == 'B0402' || options.parent == 'B0403') {
                        if (options.option == '1') {
                            options.enable['op_no'] = true;
                            options.enable['process'] = false;
                        }
                    }

                } else {
                    $rootScope.showAlert('Error : plot_detail is empty');
                }

                $MMWService.PNIGList = {};
                var badcodeList = [];

                function subReworkInfoGet(content, feedback) {
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_WIP.sub_rewok_info_get',
                        content: content,
                        success: function (data) {
                            feedback(data);
                        }
                    });
                }

                //執行重工
                // 20230323 modify by ShengKun for M# 0129412: 生产批在工位机报废进入序号处置，序号处置未判定，工作平台可以进行跳站、跳流程
                function reworkInfoProcess(dialog) {
                    var content = {
                        machine_no: options.machine_no,
                        option: options.option,
                        description: dialog.reworkInfo.description,
                        reason_detail: dialog.reworkInfo.reason_detail,
                        plot_detail: angular.copy(dialog.reworkInfo.plot_detail),
                        source_type: 2 //1: 未處置序號，判斷數量、2: 未處置序號，直接拋錯
                    };
                    // 除了 [解除暫停 重工]、[例外處理-不良品、不良現象 重工處置]、[重工處置] 以外，未處置序號 判斷數量
                    if (dialog.parent != 'B0209' && dialog.parent != 'B0402' && dialog.parent != 'B0403' && dialog.parent != 'B0302') content.source_type = 1;

                    if (dialog.parent == 'B0402') {
                        if (content.plot_detail.length) {
                            content.plot_detail.forEach(function (plot) {
                                plot.qty = plot.judge_qty;
                                delete plot.judge_qty;
                                //20220507 add by liuyang for M#111411:让步也需传process_version
                                plot.process_version = plot.process_ver;
                            });
                        }
                    } else {
                        if (content.plot_detail.length == 1) {
                            content.plot_detail[0].qty = dialog.reworkInfo.reworkQty;
                        }
                    }

                    if (dialog.reworkInfo.assign_op_no) {
                        content.assign_type = 0;
                        content.assign_op_no = dialog.reworkInfo.assign_op_no;
                        content.assign_node_id = dialog.reworkInfo.assign_process_node_id;
                    }

                    if (dialog.reworkInfo.assign_process) {
                        content.assign_type = 1;
                        content.assign_process_no = dialog.reworkInfo.assign_process;
                        content.assign_process_ver = dialog.reworkInfo.assign_process_ver;
                        content.assign_op_no = dialog.reworkInfo.assign_process_op_no;
                        content.assign_node_id = dialog.reworkInfo.assign_process_node_id;
                    }

                    if (dialog.parent == 'B0209' || dialog.parent == 'B0302') {
                        content.trigger_point = '2';
                    } else if (dialog.parent == 'B0402' || dialog.parent == 'B0403') {
                        content.trigger_point = '1';
                    } else {
                        content.trigger_point = '0';
                    }
                    if (options.confirm) {
                        options.confirm(content, dialog);
                    } else {
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.rework_info_process',
                            content: content,
                            success: function (data) {
                                //20180416 modify by 李栋 for mantis#0045407
                                // 20230926 modify by wenwei for M#131125
                                if (data.rework_lotno && data.rework_lotno != ''){
                                    $rootScope.showToast($filter('translate')('B0213.showToast_rework_lotno') + data.rework_lotno);
                                }else{
                                    $rootScope.showToast($filter('translate')('B0213.showToast'));
                                }
                                dialog.hide();
                                if (options.feedback)
                                    options.feedback();
                            }
                        });
                    }
                }
                //20180420 modify by 李栋 for mantis#0045203
                function zoom(magnification) {
                    var kmiImgPanel = document.getElementById('kmi-img-panel'),
                        kmiImgContent = document.getElementById('kmi-img-content');
                    var after_width = kmiImgPanel.width * magnification,
                        after_height = kmiImgPanel.height * magnification;
                    var after = [(after_width - kmiImgPanel.width) / 2, (after_height - kmiImgPanel.height) / 2];
                    kmiImgPanel.style.width = after_width + 'px';
                    kmiImgPanel.style.height = after_height + 'px';
                    kmiImgContent.scrollLeft = kmiImgContent.scrollLeft + after[0];
                    kmiImgContent.scrollTop = kmiImgContent.scrollTop + after[1];
                }

                function oepnOpDetail(op_detail_options) {
                    if (op_detail_options.image_url && op_detail_options.image_url != '') {
                        if (op_detail_options.image_url.indexOf('http://') == -1) {
                            op_detail_options.image_url = 'http://' + config.server.ip + ':' + config.server.port + op_detail_options.image_url;
                        }
                    }
                    var content = {
                        plot_no: op_detail_options.plot_no,
                        op_no: op_detail_options.op_no,
                        type: op_detail_options.type,
                        option: op_detail_options.option,
                        process_no: op_detail_options.assign_process,
                        process_ver: op_detail_options.assign_process_ver,
                    };
                    subReworkInfoGet(content, function (data) {
                        if (data && data.op_details.length > 0) {
                            // 20200520 modify by WeiTing for M#70293 - 修正末道製程以外的狀況會傳回多筆資料，會導致開窗多次。
                            if (data.op_details.length == 1) {
                                // 20200511 modify by WeiTing for M#70293 - 後台回傳的 op_no，如果值為 END，代表末道製程，跳確認框提示訊息。
                                if (data.op_details[0].op_no == 'END') {
                                    // 目前不良品屬於末道製程，讓步後將移至良品倉且不可報工還原，確定繼續？
                                    $rootScope.showConfirm($filter('translate')('B0213.msg.column13'), function (dialog) {
                                        dialog.hide();
                                        opdetailDialog(data, op_detail_options);
                                    });
                                }
                                else
                                    opdetailDialog(data, op_detail_options);
                            }
                            else
                                opdetailDialog(data, op_detail_options);
                        }
                        else
                            $rootScope.showAlert($filter('translate')('common.msg.no_data'));
                    });
                }

                // 指定作業站開窗
                function opdetailDialog(data, op_detail_options) {
                    //20221014 modify by wangqq for M#0120388:解除暂停后跳站指定作业站不显示END
                    if (options.parent == 'B0209') {
                        var index = data.op_details.findIndex(function (item) {
                            return item.op_no === "END";
                        })
                        delete data.op_details[index];
                    }
                    $mdDialog.dialog(
                        'module/moduleB/program/B02/B0213/B0213.opdetail.html',
                        function (dialog) {
                            return {
                                css_url: 'module/moduleB/program/B02/B0213/B0213.opdetail.css',
                                image_url: op_detail_options.image_url, //20181025 modify by Dustdusk for M#51703: 重工流程圖沒有顯示
                                reworkInfoList: data.op_details,
                                beforeShown: function () {
                                    //20181025 modify by Dustdusk for M#51703: 重工流程圖自動置中
                                    var content = document.getElementById('kmi-img-content');
                                    content.scrollBy(content.offsetWidth / 2, content.offsetHeight / 2);
                                },
                                back: function () {
                                    dialog.hide();
                                },
                                zoom_in: function () {
                                    zoom(1.1);
                                },
                                zoom_out: function () {
                                    zoom(0.9);
                                },
                                clickItem: function (item) {
                                    dialog.selectItem = item;
                                    dialog.confirm();
                                },
                                dbclickItem: function (item) {
                                    dialog.selectItem = item;
                                    dialog.confirm();
                                },
                                confirm: function () {
                                    if (op_detail_options.callback)
                                        op_detail_options.callback(dialog.selectItem);
                                    dialog.hide();
                                }
                            };
                        }
                    );
                };

                // 取得例外原因
                function getBadCodeList(callback) {
                    var content = {
                        page_mode: 8,
                        query_condition_info: []
                    };
                    if (options.option == '0') {
                        content.query_condition_info.push({ column_name: 'ReasonType', query_mode: 0, value: 9, merge_condition_model: 'AND' });
                    } else if (options.option == '1') {
                        content.query_condition_info.push({ column_name: 'ReasonType', query_mode: 0, value: 14, merge_condition_model: 'AND' });
                    }
                    $MMWService.pageNumberInfoGet(content, function (itemList) {
                        badcodeList = itemList;
                        if (callback)
                            callback();
                    });
                }

                //取得是否設定單位轉換
                function getUnitConversion(callback) {
                    if (options.enable['process']) {
                        var content = {
                            page_mode: 32,
                            query_condition_info: [
                                { column_name: 'b.LotNo', query_mode: '0', value: plotItem.plot_no, merge_condition_model: "AND" }
                            ]
                        };
                        $MMWService.pageNumberInfoGet(content, function (itemList) {
                            if (itemList && itemList.length > 1) { // 大於1筆表示有設定單位轉換
                                plotItem.unit_conversion = 1;
                            }
                            if (callback)
                                callback();
                        });
                    } else {
                        if (callback)
                            callback();
                    }
                }

                // 檢查生產批是否集中
                function checkPlotConcentrated(callback) {
                    // 僅跳流程需要檢查
                    if (options.option == '3') {
                        var content = {
                            page_mode: 41,
                            query_condition_info: [{ column_name: 'lotno', query_mode: 0, value: plotItem.plot_no, merge_condition_model: 'AND' }]
                        };
                        $MMWService.pageNumberInfoGet(content, function (itemList) {
                            if (itemList && itemList.length > 0) {
                                if (itemList[0].page_no <= 0) {
                                    $rootScope.showAlert($filter('translate')('B0213.msg.column11')); //異常操作!找不到生產批資料!
                                } else if (itemList[0].page_no > 1) {
                                    $rootScope.showAlert($filter('translate')('B0213.msg.column12')); //生產批未集中，不允許跳流程！
                                } else {
                                    if (callback)
                                        callback();
                                }
                            } else {
                                $rootScope.showAlert($filter('translate')('B0213.msg.column11')); //異常操作!找不到生產批資料!
                            }
                        });
                    } else {
                        if (callback)
                            callback();
                    }
                }

                // 檢查指定作業站清單是否為空
                function checkAssignOpList(callback) {
                    // 若重工類型僅可指定作業站時，開窗前需檢查是否有作業站可供選擇
                    if (options.enable['op_no'] && !options.enable['process']) {
                        var content = {
                            plot_no: plotItem.plot_no,
                            op_no: plotItem.op_no,
                            type: '0',
                            option: options.option
                        };
                        subReworkInfoGet(content, function (data) {
                            if (!data.op_details || data.op_details.length <= 0) {
                                var msg = $filter('translate')('B0213.msg.column9'); //查無作業站可供指定，不允許此操作
                                if (options.option == '1')
                                    msg += $filter('translate')('B0213.msg.column10'); //應是生產批處於末道作業站無法進行讓步處置
                                $rootScope.showAlert(msg);

                                if (options.parent == 'B0209' && options.back) {
                                    options.back(options.plot_detail[0], options.feedback);
                                }
                            } else {
                                if (callback)
                                    callback();
                            }
                        });
                    } else {
                        if (callback)
                            callback();
                    }
                }

                function beforeOpenDialog(callback) {
                    checkAssignOpList(function () {
                        checkPlotConcentrated(function () {
                            getBadCodeList(function () {
                                getUnitConversion(function () {
                                    if (callback)
                                        callback();
                                });
                            });
                        });
                    });
                }

                var openDialog = function () {
                    $mddProvider.UseForm('B0213Service', () => {
                        $mdDialog.dialog(
                            'module/moduleB/program/B02/B0213/B0213.html',
                            function (dialog) {
                                let _hide = dialog.hide;
                                return {
                                    css_url: 'JSplugins/angular-material-lite/template/dynamicService.tmp.css',
                                    B13_title: 'B0213.title_' + options.option,
                                    enable: options.enable,
                                    parent: options.parent,
                                    rework_type: options.option,
                                    reworkInfo: plotItem,
                                    only_product_process: '1',
                                    _title: 'B0213.title_' + options.option,
                                    _event: {
                                        'description': {
                                            isShown: options.enable.memo ? 'Y' : 'N'
                                        },
                                        // 20230901 delete by wenwei for M# 144153: [Oracle][6.0][在线][D10-暫停]重工跳流程-仅显示产品流程为否
                                        'op_no': {
                                            isShown: options.parent == 'B0402' ? 'N' : 'Y'
                                        },
                                        'plot_no': {
                                            isShown: options.parent == 'B0402' ? 'N' : 'Y'
                                        },
                                        'assign_op_name': {
                                            isShown: options.enable.op_no ? 'Y' : 'N',
                                            //20180420 modify by 李栋 for mantis#0045203
                                            click: () => {
                                                var content = {
                                                    LotNo: dialog.reworkInfo.plot_no,
                                                    OPNo: dialog.reworkInfo.op_no
                                                };
                                                $MMWService.sendToServer({
                                                    uri: 'ServicesSTD.Module_WIP.plot_display_info_get',
                                                    content: content,
                                                    success: function (data) {
                                                        oepnOpDetail({
                                                            image_url: data.flow_chart_url,
                                                            plot_no: dialog.reworkInfo.plot_no,
                                                            op_no: dialog.reworkInfo.op_no,
                                                            type: '0',
                                                            option: options.option,
                                                            callback: function (selectItem) {
                                                                dialog.reworkInfo.assign_op_no = selectItem.op_no;
                                                                dialog.reworkInfo.assign_op_name = selectItem.op_name;
                                                                dialog.reworkInfo.assign_process_node_id = selectItem.node_id;

                                                                if (selectItem.op_no == 'END') {
                                                                    dialog.reworkInfo.assign_op_name = selectItem.op_no;
                                                                }
                                                                //將指定流程/工作站清空
                                                                dialog.reworkInfo.assign_process = '';
                                                                dialog.reworkInfo.assign_process_op_no = '';
                                                                dialog.reworkInfo.assign_process_op_name = '';
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        },
                                        'assign_process': {
                                            isShown: options.enable.process ? 'Y' : 'N',
                                            isDisabled: options.option == '1'?'Y':'N',
                                            click: () => {
                                                var content = {
                                                    plot_no: dialog.reworkInfo.plot_no,
                                                    op_no: dialog.reworkInfo.op_no,
                                                    type: 3 // 20231117 add by shiwl for M# 0146236: 重工获取流程异常
                                                    // 20230901 delete by wenwei for M# 144153: [Oracle][6.0][在线][D10-暫停]重工跳流程-仅显示产品流程为否
                                                };
                                                if (dialog.parent === 'B0209') { content.jump_process_type = 'wait' }
                                                subReworkInfoGet(content, function (data) {
                                                    $rootScope.showQueryList({
                                                        pageRecord: 25,
                                                        header: [
                                                            { label: $filter('translate')('common.queryList.process_no'), code: 'process_no' },
                                                            { label: $filter('translate')('common.queryList.process_name'), code: 'process_name' },
                                                            { label: $filter('translate')('common.queryList.process_ver'), code: 'process_ver' },
                                                            { label: $filter('translate')('common.queryList.description'), code: 'description' }
                                                        ],
                                                        query: function (conditions, feedback) {
                                                            feedback(data.process_details);
                                                        },
                                                        confirm: function (selectItem, radioDialog) {
                                                            radioDialog.hide();
                                                            dialog.reworkInfo.assign_op_no = ''; //將工作站清空
                                                            dialog.reworkInfo.assign_op_name = ''; //將工作站清空

                                                            dialog.reworkInfo.assign_process = selectItem.process_no;
                                                            dialog.reworkInfo.assign_process_ver = selectItem.process_ver;

                                                            //強迫選擇指定流程的作業站
                                                            // dialog.loadProcessOplList();
                                                            //20180420 modify by 李栋 for mantis#0045203
                                                            dialog._event['assign_process_op_name'].click();//dialog.loadProcessOplListAndImage();
                                                        }
                                                    });
                                                });
                                            }
                                        },
                                        'assign_process_op_name': {
                                            isShown: options.enable.process ? 'Y' : 'N',
                                            isDisabled: options.option == '1' ? 'Y' : 'N',
                                            //20180420 modify by 李栋 for mantis#0045203
                                            click: () => {
                                                if (dialog.reworkInfo.assign_process != '') {
                                                    var content = {
                                                        LotNo: dialog.reworkInfo.plot_no,
                                                        OPNo: dialog.reworkInfo.op_no,
                                                        process_no: dialog.reworkInfo.assign_process,
                                                        process_version: dialog.reworkInfo.assign_process_ver
                                                    };
                                                    $MMWService.sendToServer({
                                                        uri: 'ServicesSTD.Module_WIP.plot_display_info_get',
                                                        content: content,
                                                        success: function (data) {
                                                            oepnOpDetail({
                                                                image_url: data.flow_chart_url,
                                                                assign_process: dialog.reworkInfo.assign_process,
                                                                assign_process_ver: dialog.reworkInfo.assign_process_ver,
                                                                type: '2',
                                                                callback: function (selectItem) {
                                                                    dialog.reworkInfo.assign_process_op_no = selectItem.op_no;
                                                                    dialog.reworkInfo.assign_process_op_name = selectItem.op_name;
                                                                    dialog.reworkInfo.assign_process_node_id = selectItem.node_id;

                                                                    //將工作站清空
                                                                    dialog.reworkInfo.assign_op_no = '';
                                                                    dialog.reworkInfo.assign_op_name = '';
                                                                }
                                                            });
                                                        }
                                                    });
                                                } else {
                                                    $rootScope.showAlert($filter('translate')('B0213.msg.column6'));
                                                }
                                            }
                                        },
                                        'dialog.reason_detail.reason_display': {
                                            displayText: $filter('translate')('B0213.rework_reason_' + options.option),
                                            click: (item, event) => {
                                                dialog.loadReworkReasonList(event.index, item);
                                            }
                                        },
                                        'reason_detail': {
                                            isShown: options.enable.reason_detail ? 'Y' : 'N'
                                        }
                                    },
                                    _fn: {
                                        'AddRow': {
                                            isShown: options.enable.reason_detail ? 'Y' : 'N',
                                            click: () => {
                                                $rootScope.showQueryList({
                                                    key: 'page_no',
                                                    title: $filter('translate')('B0213.reworkReason_select_' + dialog.rework_type),
                                                    header: [
                                                        { label: $filter('translate')('common.queryList.reason_c'), code: 'page_no' },
                                                        { label: $filter('translate')('common.queryList.reason_n'), code: 'page_name' }
                                                    ],
                                                    query: function (conditions, feedback) {
                                                        feedback(badcodeList);
                                                    },
                                                    confirm: function (selectItem, radioDialog) {
                                                        dialog.reworkInfo.reason_detail.push({
                                                            reason_no: selectItem.page_no,
                                                            page_no: selectItem.page_no,
                                                            page_name: selectItem.page_name,
                                                            reason_display: selectItem.page_no + ' ' + selectItem.page_name  // 20231207 modify by shiwl for M#0152540: 利达机电，测试区。不良现象判定这里显示异常
                                                        });
                                                        radioDialog.hide();
                                                    }
                                                });
                                            }
                                        },
                                        'Confirm': {
                                            click: () => {
                                                var msg = '';
                                                if ((+dialog.reworkInfo.reworkQty) > (+dialog.reworkInfo.qty)) {
                                                    //20220530 modify by 翰鴻 for M#110730                                        
                                                    var str_qty1 = $filter('translate')('B0213.qty');
                                                    str_qty1 = str_qty1.substring(0, str_qty1.length - 1);
                                                    var str_qty2 = $filter('translate')((dialog.parent == 'B0209') ? 'B0213.transQty' : 'B0213.reworkQty_' + dialog.rework_type);
                                                    str_qty2 = str_qty2.substring(0, str_qty2.length - 1);
                                                    msg += (str_qty2 + $filter('translate')('B0213.msg.column14') + str_qty1 + '<br>');
                                                }

                                                if (isNaN(parseInt(dialog.reworkInfo.reworkQty))) {
                                                    msg += $filter('translate')('B0213.msg.column2') + '<br>';
                                                }

                                                if (dialog.reworkInfo.assign_op_no == '' && dialog.reworkInfo.assign_process == '') {
                                                    if (options.parent == 'B0209' && options.option == '3') {//跳流程
                                                        msg += $filter('translate')('B0213.msg.column8') + '<br>';
                                                    } else if ((options.parent == 'B0209' || options.parent == 'B0403') && (options.option == '1' || options.option == '2')) {//讓步/跳站
                                                        msg += $filter('translate')('B0213.msg.column7') + '<br>';
                                                    } else {
                                                        msg += $filter('translate')('B0213.msg.column3') + '<br>';
                                                    }
                                                } if (dialog.reworkInfo.assign_process != '' && dialog.reworkInfo.assign_process_op_no == '') {
                                                    msg += $filter('translate')('B0213.msg.column5') + '<br>';
                                                }

                                                if (!(options.parent == 'B0209' && options.option != '0')) {
                                                    if (dialog.reworkInfo['reason_detail'].length == 0) {
                                                        msg += $filter('translate')('B0213.msg.column4') + '<br>';
                                                    } else {
                                                        for (var i = 0; i < dialog.reworkInfo.reason_detail.length; i++) {
                                                            var reason = dialog.reworkInfo.reason_detail[i];
                                                            if (reason.reason_no == '') {
                                                                msg += $filter('translate')('B0213.msg.column4') + '<br>';
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                if (msg != '') {
                                                    $rootScope.showAlert(msg);
                                                } else {
                                                    reworkInfoProcess(dialog);
                                                }
                                            }
                                        }
                                    },
                                    loadReworkReasonList: function (index, detail) {
                                        $rootScope.showQueryList({
                                            key: 'page_no',
                                            title: $filter('translate')('B0213.reworkReason_select_' + dialog.rework_type),
                                            header: [
                                                { label: $filter('translate')('common.queryList.reason_c'), code: 'page_no' },
                                                { label: $filter('translate')('common.queryList.reason_n'), code: 'page_name' }
                                            ],
                                            query: function (conditions, feedback) {
                                                feedback(badcodeList);
                                            },
                                            confirm: function (selectItem, radioDialog) {
                                                radioDialog.hide();

                                                dialog.reworkInfo.reason_detail[index].reason_no = selectItem.page_no;
                                                dialog.reworkInfo.reason_detail[index].page_no = selectItem.page_no;
                                                dialog.reworkInfo.reason_detail[index].page_name = selectItem.page_name;
                                                dialog.reworkInfo.reason_detail[index].reason_display = selectItem.page_no + ' ' + selectItem.page_no;
                                            }
                                        });
                                    },
                                    changeOnlyProductProcess: function () {
                                        dialog.only_product_process = !dialog.only_product_process;
                                    },
                                    removeRow: function (index) {
                                        dialog.reworkInfo.reason_detail.splice(dialog.reworkInfo.reason_detail.indexOf(dialog.reworkInfo.reason_detail[index]), 1);
                                    },
                                    // 20230901 delete by wenwei for M# 144153: [Oracle][6.0][在线][D10-暫停]重工跳流程-仅显示产品流程为否
                                    back: function () {
                                        _hide();
                                        if (options.parent == 'B0209' && options.back) {
                                            options.back(options.plot_detail[0], options.feedback);
                                        }
                                    }
                                    // 20230316 remove by Alan for #130378: hide時不應該跳回解除暫停
                                };
                            }
                        );
                    })

                };

                (function () {
                    beforeOpenDialog(function () {
                        openDialog();
                    });
                })();
            };
        }]);
});
